package com.itheima.pinda.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.pinda.DTO.entity.PdCoreStation;
import com.itheima.pinda.mapper.PdCoreStationMapper;
import com.itheima.pinda.service.PdCoreStationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

import java.util.Map;

/**
 * <p>
 * 岗位 服务实现类
 * </p>
 *
 * @author xsf
 * @since 2021-11-11
 */
@Service
public class PdCoreStationServiceImpl extends ServiceImpl<PdCoreStationMapper, PdCoreStation> implements PdCoreStationService {

    @Autowired
    private PdCoreStationMapper pdCoreStationMapper;
    @Override
    public IPage<PdCoreStation> queryByPage(Map<String, Object> map) {
        int size = Integer.valueOf(map.get("size")+"");
        int current = Integer.valueOf(map.get("current")+"");

        QueryWrapper<PdCoreStation> queryWrapper = new QueryWrapper<>();
        Object name = map.get("name");
        if(!ObjectUtils.isEmpty(name)){
            queryWrapper.like("name",name);
        }

        Object orgIdStr = map.get("orgId");
        if(!ObjectUtils.isEmpty(orgIdStr)){
            queryWrapper.like("org_id",orgIdStr);
        }

        Object startCreateTimeStr = map.get("startCreateTime");
        if(!ObjectUtils.isEmpty(startCreateTimeStr)){
            queryWrapper.apply("UNIX_TIMESTAMP(create_time) >= UNIX_TIMESTAMP('" + startCreateTimeStr + "')");
        }

        Object endCreateTimeStr = map.get("endCreateTime");
        if(!ObjectUtils.isEmpty(endCreateTimeStr)){
            queryWrapper.apply("UNIX_TIMESTAMP(create_time) < UNIX_TIMESTAMP('" + endCreateTimeStr + "')");
        }
        IPage<PdCoreStation> iPage = new Page<>(current,size);
        IPage<PdCoreStation> page = pdCoreStationMapper.selectPage(iPage, queryWrapper);

        return page;
    }
}
